package com.financing.wap.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.financing.wap.common.Session;
import com.financing.wap.common.SessionUtil;
import com.financing.wap.common.Views;
import com.financing.wap.dto.FaUserDTO;
import com.financing.wap.dto.UserDTO;
import com.financing.wap.service.IUserService;
import com.financing.wap.util.SelectUtils;

/**
 * 登陆API
 * @author localadmin
 *
 */
@Controller
@RequestMapping("/user")
public class UserController extends BaseController {


	@Autowired
	private IUserService userService;

	@RequestMapping("center")
	public String center(){

		return Views.USER_CENTER;
	}

	@RequestMapping("view")
	public String view(HttpServletRequest request, HttpServletResponse response){

		Session session = getSession(true);
		UserDTO loginUser = session.getUser();
		//当前登录人ID
		String faId = loginUser.getId();
		
		FaUserDTO faUser = userService.getUserById(faId);
		request.setAttribute("selectCertType", SelectUtils.getSelectCertType());
		request.setAttribute("selectSex", SelectUtils.getSelectSex());
		request.setAttribute("user", faUser);
		return Views.USER_VIEW;
	}

	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(HttpServletRequest request, HttpServletResponse response){

		this.view(request, response);
		return Views.USER_EDIT;
	}

	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public String editPost(HttpServletRequest request, HttpServletResponse response,FaUserDTO faUser){
		Session session = SessionUtil.getSession();
		UserDTO loginUser = session.getUser();
		//当前登录人ID
		String faId = loginUser.getId();
		faUser.setUpdateBy(faId.toString());
		userService.updateFaUserInfo(faUser);
		
		return "redirect:/user/view";
	}
	
}
